package com.tuzhi.sys.web.controller;


import com.tuzhi.base.jpa.domain.Pager;
import com.tuzhi.base.service.BaseService;
import com.tuzhi.base.web.controller.SimpleBaseController;
import com.tuzhi.base.web.helper.AjaxResultHelper;
import com.tuzhi.base.web.vo.AjaxResultVO;
import com.tuzhi.base.web.vo.PageVO;
import com.tuzhi.sys.jpa.entity.SystemLogEntity;
import com.tuzhi.sys.service.SystemLogService;
import com.tuzhi.sys.vo.query.QuerySystemLogVo;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@RestController("/syslog")
@Api(tags = "系统日志")
@RequiredArgsConstructor()
public class SystemLogController extends SimpleBaseController<SystemLogEntity, Long, SystemLogEntity> {

    private final SystemLogService systemLogService;
    @Override
    protected BaseService getThisService() {
        return systemLogService;
    }

    @GetMapping("/page")
    public AjaxResultVO<Pager<SystemLogEntity>> getPage(PageVO<QuerySystemLogVo> request) {
        Pager<SystemLogEntity> resultPage = systemLogService.getPage(request);
        return AjaxResultHelper.success().ofData(resultPage);
    }


    /**
     * 心跳接口查询
     *
     * @return
     */
    @GetMapping("/testing")
    @Override
    public AjaxResultVO test() {
        log.info("心跳接口测试，接口正常");
        AjaxResultVO ajaxResultVO = AjaxResultHelper.success();
        ajaxResultVO.setMsg("心跳接口测试，接口正常:");
        ajaxResultVO.setData(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        return ajaxResultVO;
    }


}
